<?php

/*

Process Bidding (auctions_bid.pro.php)

*/
ob_start();
include "global.inc.php";

$findAuction = fetch("SELECT * FROM auctions2 WHERE id = '$id' AND game = '$game'");
$minBid = $findAuction[high_bid] + $findAuction[min_increment];

if ($bid_value < $minBid)
{
	die(header(error("auctions_bid.php?game=$game&id=$id","You must bid at least $minBid $pointsVar!")));
}

if ($bid_value > $points)
{
	die(header(error("auctions_bid.php?game=$game&id=$id","You do not have enough points to bid that much.")));
}

if ($username == $findAuction[owner])
{
	die(header(error("auctions_bid.php?game=$game&id=$id","Please do not bid on your own auctions.")));
}

if ($bid_value <= 0)
{
	die(header(error("auctions_bid.php?game=$game&id=$id","You must bid at least 0 $pointsVar!")));
}

points($game, "$username", "-$bid_value");

mysql_query("UPDATE auctions2 SET high_bid=$bid_value WHERE id = '$id' AND game = '$game'");
mysql_query("UPDATE auctions2 SET high_bidder = '$username' WHERE id = '$id' AND game = '$game'");
mysql_query("UPDATE auctions2 SET bids=$findAuction[bids]+1 WHERE id = '$id' AND game = '$game'");

$findHigh = fetch("SELECT id FROM members2 WHERE username = '$findAuction[high_bidder]' AND game = '$game'");
if ($findHigh[id])
{
	systemmessage("$game", "auctions_bid.php?game=$game&id=$id","$findHigh[id]","You have been out bid on the $findAuction[item_name].<br>Your $findAuction[high_bid] $pointsVar have been added back to your account.");
	points($game, "$findAuction[high_bidder]", "$findAuction[high_bid]");
}

die(header(error("auctions_bid.php?game=$game&id=$id","You have put your bid of $bid_value in.<br>You will get this money back if someone out bids you.")));

?>